import sys
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By

sys.path.append(r'..')
from web_base.base_page import BasePage


class BaiduPage(BasePage):
    url = r'https://www.baidu.com'
    # 搜索定位
    kw_loc = (By.ID, 'kw')
    su_loc = (By.ID, 'su')
    # 登录定位
    login_btn_loc = (By.XPATH, '//*[@id="s-top-loginbtn"]')
    username_loc = (By.ID, 'TANGRAM__PSP_11__userName')
    password_loc = (By.ID, 'TANGRAM__PSP_11__password')
    isagree_loc = (By.ID, 'TANGRAM__PSP_11__isAgree')
    login_submit_loc = (By.ID, 'TANGRAM__PSP_11__submit')
    #hao123定位
    hao123_loc=(By.XPATH,'/html/body/div[2]/div[1]/div[3]/a[2]')
    def __init__(self, driver):
        super().__init__(driver)  # 将driver传给父类
        self.get_url(self.url)
        self.ele_max()

    def search(self, kw):
        self.ele_clear(self.kw_loc)
        self.input_ele(self.kw_loc, kw)
        self.click_ele(self.su_loc)
        sleep(3)

    def login(self, username, password):
        self.click_ele(self.login_btn_loc)
        sleep(3)
        self.ele_clear(self.username_loc)
        self.input_ele(self.username_loc, username)
        self.ele_clear(self.password_loc)
        self.input_ele(self.password_loc, password)
        self.click_ele(self.isagree_loc)
        self.click_ele(self.login_submit_loc)
        sleep(3)
    def hao123(self):
        self.click_ele(self.hao123_loc)
        sleep(3)


if __name__ == '__main__':
    kw = 'selenium'
    username = '123'
    password = '456'
    chrome_location = r'E:\nmon\light_Chrome\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location

    driver = webdriver.Chrome(options=options)
    baidu_page = BaiduPage(driver)
    # 测试搜索
    # baidu_page.search(kw)
    #测试登录
    # baidu_page.assert(username,password)
    #测试hao123
    baidu_page.hao123()
    driver.quit()
